﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DAL.DateSet.BuildingTableAdapters;
using DAL;
using DAL.DateSet;
namespace BLL.Wrapper
{
    public class BuildingWrapper : BuildingTableAdapter
    {
        public Building.BuildingDataTable getAll()
        {
            return GetData();
        }

        public void addARecord(Building.BuildingRow row)
        {
            Insert(row.cantavilID,row.buildingNum,row.buildingType,row.buildingPic,row.buildingRemark,row.buildingCreator,row.buildingCreateDate);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from Builidng where buildingID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.insert(sql);
        }

        public void updateArecord(Building.BuildingRow row)
        {
            Building.BuildingDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["buildingID"].ToString()) == row.buildingID)
                {
                    table.Rows[i]["cantavilID"] = row.cantavilID;
                    table.Rows[i]["buildingCreateDate"] = row.buildingCreateDate;
                    table.Rows[i]["buildingCreator"] = row.buildingCreator;
                    table.Rows[i]["buildingNum"] = row.buildingNum;
                    table.Rows[i]["buildingPic"] = row.buildingPic;
                    table.Rows[i]["buildingRemark"] = row.buildingRemark;
                    table.Rows[i]["buildingType"] = row.buildingType;
                    break;
                }
            }
            Update(table);
        }
    }
}
